from .base import db
from datetime import datetime

class TrainingExperience(db.Model):
    __tablename__ = 'training_experience'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    employee_id = db.Column(db.Integer, db.ForeignKey('employee.id'), nullable=False)
    course_name = db.Column(db.String(255), nullable=False)
    organization = db.Column(db.String(255), nullable=False)
    start_date = db.Column(db.String(32), nullable=False)
    end_date = db.Column(db.String(32), nullable=False)
    certificate = db.Column(db.String(255))
    created_at = db.Column(db.DateTime, default=datetime.utcnow)
    updated_at = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)

    def to_dict(self):
        return {
            'id': self.id,
            'employee_id': self.employee_id,
            'course_name': self.course_name,
            'organization': self.organization,
            'start_date': self.start_date,
            'end_date': self.end_date,
            'certificate': self.certificate,
            'created_at': self.created_at.isoformat() if self.created_at else None,
            'updated_at': self.updated_at.isoformat() if self.updated_at else None
        } 